<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input v-model="listQuery.keywords" placeholder="关键字/id/小组名称" style="width: 200px;" class="filter-item"
        @keyup.enter.native="handleFilter" />
      <el-select v-model="listQuery.address_id" placeholder="地区选择" clearable style="width: 150px" class="filter-item">
        <el-option v-for="(item, index) in address" :key="index" :label="item.name" :value="item.id" />
      </el-select>
      <el-select v-model="listQuery.order" placeholder="排序规则" clearable style="width: 150px" class="filter-item">
        <el-option v-for="(item, index) in order" :key="index" :label="item" :value="index" />
      </el-select>
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="getList">搜索</el-button>
    </div>
    <el-table :key="tableKey" v-loading="listLoading" :data="list" border fit highlight-current-row style="width: 100%;">
      <el-table-column label="ID" prop="id" sortable="custom" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="会员id" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.headman }}</span>
        </template>
      </el-table-column>
      <el-table-column label="会员昵称" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.member_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="会员手机号码" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.member_phone }}</span>
        </template>
      </el-table-column>
      <el-table-column label="小组名称" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="小组介绍" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.describe }}</span>
        </template>
      </el-table-column>
      <!--      <el-table-column label="试卷封面" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.image">
            <img width="100px" :src="qiniuDomain + scope.row.image"></img>
          </span>
          <span v-else>
            无
          </span>
        </template>
      </el-table-column> -->
      <el-table-column label="所属地区" align="center">
        <template slot-scope="scope">
          <span>{{ addressA[scope.row.address_id] }}</span>
        </template>
      </el-table-column>
      <el-table-column label="成员数" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.number_member }}</span>
        </template>
      </el-table-column>
      <el-table-column label="主题数" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.number_theme }}</span>
        </template>
      </el-table-column>
      <el-table-column label="添加日期" align="center">
        <template slot-scope="{ row }">
          {{ _date(row.create_time) }}
        </template>
      </el-table-column>
      <el-table-column label="操作" width="300" align="center">
        <template slot-scope="scope">
          <el-button size="small" type="primary" @click="theme_list(scope.row)">主题</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
  </div>
</template>
<script>
  import {
    groupList,
    groupEdit
  } from '@/api/group';
  import {
    addressList
  } from '@/api/config';
  import waves from '@/directive/waves';
  import Pagination from '@/components/Pagination';
  import permission from '@/directive/permission/index.js';
  import {
    dateHandle
  } from '@/api/dateHandle';
  import imageUpload from '@/components/Upload/image';


  export default {
    components: {
      Pagination,
      imageUpload
    },
    directives: {
      waves,
      permission,

    },
    data() {
      return {
        tableKey: 0,
        list: null,
        total: 0,
        listLoading: true,
        listQuery: {
          page: 1,
          limit: 20,
        },
        address: {},
        addressA: [],
        item: {},
        order: {
          number_member: '成员数',
          number_theme: '主题数',
          id: '最新',
        },

      };
    },
    created() {
      this.getList()
      this.getAddress()
    },
    methods: {
      _date(t) {
        return dateHandle('Y-m-d H:i:s', t);
      },
      theme_list(item) {
        this.$router.push({
          name: 'group/themeList',
          params: {
            id: item.id,
            name: item.name
          }
        })
      },

      getAddress() {
        addressList().then(res => {
          this.address = res.data
          res.data.forEach(i => {
            this.addressA[i.id] = i.name
          })
          console.log(this.addressA);
        })
      },

      getList() {
        this.listLoading = true;
        groupList(this.listQuery).then(res => {
          this.list = res.data.data;
          this.total = res.data.total;
          setTimeout(() => {
            this.listLoading = false;
          }, 0.3 * 1000);
        });
      },

    }
  };
</script>
